package game;

import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.Trigger;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import ui.JournalScreenController;

public class InGameInputHandler implements ActionListener, MyInputListener {
    protected Map<String, Trigger> inputMappings = new HashMap<String, Trigger>();

    public InGameInputHandler() {
        inputMappings.put("Journal", new KeyTrigger(KeyInput.KEY_J));

        for(Entry<String, Trigger> mapping : inputMappings.entrySet()) {
            if(!DataStore.inputManager.hasMapping(mapping.getKey()))
                DataStore.inputManager.addMapping(mapping.getKey(), mapping.getValue());
        }
    }

    public void register() {
        for(String event : inputMappings.keySet())
            DataStore.inputManager.addListener(this, event);
    }

    public void onAction(String name, boolean isPressed, float tpf) {
        if(isPressed) {
	    if(name.equals("Journal")) {
                toggleJournal();
	    }
        }
    }
    
    public void toggleJournal() {
        if(DataStore.nifty.getCurrentScreen().getScreenId().equals("journal")) {
            DataStore.nifty.gotoScreen("hud");
            InputController.unpauseCurrentGameInput();
        } else {
            InputController.pauseCurrentGameInput();
            DataStore.nifty.gotoScreen("journal");
        }
    }
}
